﻿using System;
namespace Colors.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Mix", Namespace="http://colors.x-road.eu/", Target=typeof(Mix))]
    public class MixSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected Mix clazz;
        
        public MixSerializer(Mix clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("One");
            if (clazz.One!=null) {
                Writer.WriteString(clazz.One.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : One");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Other");
            if (clazz.Other!=null) {
                Writer.WriteString(clazz.Other.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Other");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="One") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Mix>One");
                }
                clazz.One = new global::Colors.Xroad.Eu.Color(Reader.ReadElementString("One"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Mix>One", Reader.LocalName);
            }
            if (Reader.LocalName=="Other") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Mix>Other");
                }
                clazz.Other = new global::Colors.Xroad.Eu.Color(Reader.ReadElementString("Other"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Mix>Other", Reader.LocalName);
            }
        }
    }
}
